package com.vlin.api.client.request.defaut;

import java.util.Map.Entry;

import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpUriRequest;

import com.vlin.api.client.Method;
import com.vlin.api.client.Params;
import com.vlin.api.client.request.RequestProducer;

public class DefaultedGETRequestProducer implements RequestProducer {
	
	//public static final String URL_TEMP = "%s?%s"; 

	@Override
	public HttpUriRequest produceRequest(String url, Method method, Params params) {
		StringBuilder sb = new StringBuilder();
		sb.append(url);
		sb.append("?");
		for(Entry<String, String> entry : params.getParams().entrySet()) {
			sb.append(entry.getKey());
			sb.append("=");
			sb.append(entry.getValue());
			sb.append("&");
		}
		url = sb.substring(0, sb.length() - 1);
		HttpGet httpGet = new HttpGet(url);
		
		for(Entry<String, String> entry : params.getHeadParams().entrySet()) {
			httpGet.addHeader(entry.getKey(), entry.getValue());
		}
		return httpGet;
	}

	@Override
	public boolean supportMethod(Method method) {
		
		return getMethod().equals(method);
	}

	@Override
	public Method getMethod() {
		
		return Method.GET;
	}

}
